package linkedlist;

import java.util.LinkedList;

public class Test1 {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);

        list.add(0,5);
        list.addFirst(6);
        System.out.println(list);//[6, 5, 1, 2, 3, 4]

        list.remove(2);// 删除索引为2的元素 1
        System.out.println(list);//[6, 5, 2, 3, 4]

        list.remove(Integer.valueOf(2));//删除值为2的元素 2
        System.out.println(list);//[6, 5, 3, 4]

        //头删
        list.removeFirst();
        System.out.println(list);//[5, 3, 4]
        //尾删
        list.removeLast();
       System.out.println(list);//[5, 3]


        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        //通过get方法获取元素
        System.out.println(list.get(2));//3
        //通过set方法修改元素
        list.set(2, 10);
        System.out.println(list);//[1, 2, 10, 4, 1, 2, 3, 4, 5]


        //通过contians方法判断是否包含元素
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println(list.contains(3));//true
        System.out.println(list.contains(6));//false

    }
}
